
#include <pic.h>
#include "my_macros.h"
#include "hardware.h"
#include "Outputs.h"


unsigned int Out_Status;

void Out_Init ( void )
{
	PIN_OUT_1     		= 0;
	PIN_OUT_1_DIR		= OUTPUT;
	PIN_OUT_2			= 0;
	PIN_OUT_2_DIR		= OUTPUT;
	PIN_OUT_3			= 0;
	PIN_OUT_3_DIR		= OUTPUT;
	PIN_OUT_4			= 0;
	PIN_OUT_4_DIR		= OUTPUT;
	PIN_OUT_5			= 0;
	PIN_OUT_5_DIR		= OUTPUT;
	PIN_OUT_6			= 0;
	PIN_OUT_6_DIR		= OUTPUT;
	PIN_OUT_7			= 0;
	PIN_OUT_7_DIR		= OUTPUT;
	PIN_OUT_8			= 0;
	PIN_OUT_8_DIR		= OUTPUT;
	PIN_OUT_9			= 0;
	PIN_OUT_9_DIR		= OUTPUT;
	PIN_OUT_10			= 0;
	PIN_OUT_10_DIR		= OUTPUT;
	PIN_OUT_11			= 0;
	PIN_OUT_11_DIR    = OUTPUT;    
	
	PIN_OUT_12			= 0;
	PIN_OUT_12_DIR    = OUTPUT;    
	
	PIN_OUT_13			= 0;
	PIN_OUT_13_DIR    = OUTPUT;    
	
	PIN_OUT_14			= 0;
	PIN_OUT_14_DIR    = OUTPUT;    
	
	/* PIN_OUT_15			= 0; */
	/* PIN_OUT_15_DIR    = OUTPUT;     */

	LED = 0;
	LED_DIR = OUTPUT;

}

/* void Out_GetStatus ( char* Str )  */
/* { */
/* 	unsigned char i; */
/* 	unsigned int mask = 1; */

/* 	for ( i = 0; i < OUTPUTS__AMOUNT; i++ ) */
/* 	{ */
/* 		if ( Out_Status & mask ) */
/* 		{ */
/* 			Str[i] = '1'; */
/* 		}  */
/* 		else */
/* 		{ */
/* 			Str[i] = '0'; */
/* 		} */

/* 		mask <<= 1; */
/* 	} */

/* 	Str[i] = 0; */
/* } */

void Out_SetPin ( unsigned char PinNumber, unsigned char Value )
{
	switch( PinNumber )
	{
		case 1:
			PIN_OUT_1 = Value;
			break;

		case 2:
			PIN_OUT_2 = Value;
			break;

		case 3:
			PIN_OUT_3 = Value;
			break;
			
		case 4:
			PIN_OUT_4 = Value;
			break;
			
		case 5:
			PIN_OUT_5 = Value;
			break;
			
		case 6:
			PIN_OUT_6 = Value;
			break;	
			
		case 7:
			PIN_OUT_7 = Value;
			break;
			
		case 8:
			PIN_OUT_8 = Value;
			break;
			
		case 9:
			PIN_OUT_9 = Value;
			break;

		case 10:
			PIN_OUT_10 = Value;
			break;

		case 11:
			PIN_OUT_11 = Value;
			break;

		case 12:
			PIN_OUT_12 = Value;
			break;
			
		case 13:
			PIN_OUT_13 = Value;
			break;
			
		case 14:
			PIN_OUT_14 = Value;
			break;
			
		/* case 15: */
		/* 	PIN_OUT_15 = Value; */
		/* 	break; */

		default:
			;
	}
}

void Out_Drive ( void )
{
	unsigned char i;
	unsigned int mask = 1;

	for ( i = 1; i < OUTPUTS__AMOUNT; i++ )
	{
		if ( Out_Status & mask )
		{
			Out_SetPin(i, 1);
		}
		else
		{
			Out_SetPin(i, 0);
		}

		mask <<= 1;
	}
} 
